package cn.chenhuanming.shh.authentication.server;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;

/**
 * To solve the spring session bug in spring core 4.3.9
 * @see <a href="https://jira.spring.io/browse/SPR-15766">ClassCastException during deserialization of ScopedObject</a>
 *
 * Created by chenhuanming on 2017-07-20.
 * @author chenhuanming
 */
public class SerializationBeanFactoryPostProcessor implements BeanFactoryPostProcessor{

    private static final String SERIALIZATION_ID = "4086d293-522c-4d25-8485-f1c1f5c09218";

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
        if ((beanFactory instanceof DefaultListableBeanFactory)) {
            DefaultListableBeanFactory dlbf = (DefaultListableBeanFactory) beanFactory;
            dlbf.setSerializationId(SERIALIZATION_ID);
        }
    }
}
